package DAO;

import Config.GlobalVariables;
import Entity.RobotStatus;

import java.sql.*;

class DatabaseConnection {
    private static final String URL = GlobalVariables.URL;
    private static final String USERNAME = GlobalVariables.USERNAME;
    private static final String PASSWORD = GlobalVariables.PASSWORD;

    // 获取数据库连接
    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(URL, USERNAME, PASSWORD);
    }

    public static void main(String[] args) {
        try (Connection connection = DatabaseConnection.getConnection()) {
            if (connection != null) {
                System.out.println("数据库连接成功!");

                // SQL 查询语句
                String query = "SELECT * FROM products";

                try (Statement statement = connection.createStatement();
                     ResultSet resultSet = statement.executeQuery(query)) {

                    // 打印机器人的数据
                    while (resultSet.next()) {
                        String id = resultSet.getString("identifier");




                        // 打印每个机器人信息
                        System.out.println("ID: " + id);

                    }

                } catch (SQLException e) {
                    System.out.println("查询机器人信息时出错: " + e.getMessage());
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}